package xjtu.se.articlecommunity.user.myself;

import org.springframework.web.bind.annotation.*;
import xjtu.se.articlecommunity.common.CommonService;
import xjtu.se.articlecommunity.common.Result;
import xjtu.se.articlecommunity.common.TokenUtils;
import xjtu.se.articlecommunity.common.dto.CurrentUser;
import xjtu.se.articlecommunity.user.myself.MyFollowService;
import xjtu.se.articlecommunity.user.myself.dto.FollowedUser;

import javax.annotation.Resource;
import java.util.*;

@RestController
@RequestMapping("/user/myself")
public class MyFollowAPI {
    @Resource
    private MyFollowService myFollowService;
    @Resource
    private CommonService commonService;
    @GetMapping("/myfollow/{u_id}")
    public Result getFollowedUsers(@PathVariable String u_id){
        List<FollowedUser> list=myFollowService.getInfo(u_id);
       return Result.success(list);
    }

    @PostMapping ("/cancleFollow/{befollowed_u_id}")
    public Result cancleFollow(@RequestHeader("Token") String token,@PathVariable String befollowed_u_id){
        CurrentUser currentUser = TokenUtils.getUserInfo(token, commonService);
        myFollowService.cancleFollow(currentUser.getU_id(),befollowed_u_id);
        return Result.success();
    }

    @GetMapping("/fans/{u_id}")
    public Result getFans(@PathVariable String u_id){
        List<FollowedUser> list=myFollowService.getFansInfo(u_id);
        return Result.success(list);
    }








}
